﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class TransactionDAO : BaseService
    {
        #region 得到单个用户余额信息
        /// <summary>
        /// 得到单个用户余额信息byUserid
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<Transaction> GetTransaByUserId(int userid, int page, int pagesize)
        {
            string hql = "from Transaction where UserId =" + userid + " Order by AddDate Desc,Id desc";
            return FindList<Transaction>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 得到单个用户余额信息总数byUserid
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public int GetTransaByUserId(int userid)
        {
            string hql = "select count(*) from Transaction where UserId =" + userid;
            return Convert.ToInt32(GetValue(hql));
        }
        #endregion

        public Transaction GetMaxTran(int userId)
        {
            string hql = "from Transaction where UserId =" + userId + " Order by Id Desc";
            try
            {
                return FindList<Transaction>(hql, null, 0, 1)[0];
            }
            catch (Exception)
            {

                return null;
            }
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="tr"></param>
        /// <returns></returns>
        public bool InsertTrans(Transaction tr)
        {
            try {
                DBHelper.TransInsert(tr);
                return true;
            }
            catch { return false; }
        }

    }
}
